<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import infoAdv from '@/api/info/infoAdv'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  infoAdv.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  infoAdv.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'info_adv',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: infoAdv.getList,
  recycleApi: infoAdv.getRecycleList,
  add: {
    show: true,
    api: infoAdv.save,
    auth: ['info:adv:save']
  },
  edit: {
    show: true,
    api: infoAdv.update,
    auth: ['info:adv:update']
  },
  delete: {
    show: true,
    api: infoAdv.deletes,
    auth: ['info:adv:delete'],
    realApi: infoAdv.realDeletes,
    realAuth: ['info:adv:realDeletes']
  },
  recovery: {
    show: true,
    api: infoAdv.recoverys,
    auth: ['info:adv:recovery']
  },
  import: {
    show: true,
    url: 'info/adv/import',
    templateUrl: 'info/adv/downloadTemplate',
    auth: ['info:adv:import']
  },
  export: {
    show: true,
    url: 'info/adv/export',
    auth: ['info:adv:export']
  }
})

const columns = reactive([
  {
    title: "广告自增标识编号",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入广告自增标识编号"
    }
  },
  {
    title: "广告位id",
    dataIndex: "ap_id",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入广告位id"
    }
  },
  {
    title: "广告内容描述",
    dataIndex: "adv_title",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入广告内容描述"
    }
  },
  {
    title: "广告图片",
    dataIndex: "up_img",
    formType: "input"
  },
  {
    title: "广告内容",
    dataIndex: "adv_content",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入广告内容"
    }
  },
  {
    title: "跳转",
    dataIndex: "jump_url",
    formType: "input"
  },
  {
    title: "广告开始时间",
    dataIndex: "adv_start_time",
    formType: "date",
    showTime: true
  },
  {
    title: "广告结束时间",
    dataIndex: "adv_end_time",
    formType: "date",
    showTime: true
  },
  {
    title: "幻灯片排序",
    dataIndex: "order_sort",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入幻灯片排序"
    }
  },
  {
    title: "广告点击率",
    dataIndex: "click_num",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入广告点击率"
    }
  },
  {
    title: "会员购买的广告是否通过审核0未审核1审核已通过2审核未通过",
    dataIndex: "is_allow",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入会员购买的广告是否通过审核0未审核1审核已通过2审核未通过"
    }
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "状态",
    dataIndex: "status",
    formType: "input"
  },
  {
    title: "创建时间",
    dataIndex: "create_time",
    formType: "input",
    search: true,
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "更新时间",
    dataIndex: "update_time",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'info:adv' } </script>